package cn.hjh.rpc.consumer;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class TempRpcMessageListner implements MessageListener
{

	private AmqpTemplate amqpTemplate;
	
	@Override
	public void onMessage(Message message)
	{
		System.out.println("接受到的消息为 : " + new String(message.getBody()));
		
		String msge = "模拟rpc服务端消息返回";
		Message messageResp = new Message(msge.getBytes(), message.getMessageProperties());
		
//		try
//		{
//			Thread.sleep(4000);
//		} catch (InterruptedException e)
//		{
//			e.printStackTrace();
//		}
		String routingKey = message.getMessageProperties().getReplyTo();
		amqpTemplate.send(routingKey, messageResp);
		System.out.println("应答结束");
	}

	public AmqpTemplate getAmqpTemplate()
	{
		return amqpTemplate;
	}

	public void setAmqpTemplate(AmqpTemplate amqpTemplate)
	{
		this.amqpTemplate = amqpTemplate;
	}

}
